// components/video/cmp.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    src:String,
    poster:String,
    duration:String,
    mainTitle:String,
    videoId:String,
  },

  /**
   * 组件的初始数据
   */
  data: {
    showPoster:true,
  },

  lifetimes:{//写在lifetimes里面的生命周期函数优先级更高
    attached(){
      this._getVideoInfo()
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onPlay(){
      this._toggleVideoPoster()
      this.video.play()
    },
    onMaskTap(){
      this._toggleVideoPoster()
      this.video.seek(0)
      this.video.stop()
    },
    onVideoEnd(){
      this._toggleVideoPoster()
    },
    _toggleVideoPoster(){//抽离出来的某个函数要用到的私有方法
      this.setData({
        showPoster:!this.data.showPoster
      })
    },
    _getVideoInfo(){
      const id = this.properties.videoId
      this.video = wx.createVideoContext(id,this);
    },
  }
})
